package com.saydc.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts.action.Action;
import org.hibernate.Hibernate;
import org.hibernate.Session;

import com.saydc.model.Caracteristica;
import com.saydc.model.TipoCaracteristica;
import com.saydc.utils.HibernateUtils;

public class CaracteristicasDAO extends Action {

	private static CaracteristicasDAO instance;

	public static CaracteristicasDAO getInstance(){
		if(instance == null){
			instance = new CaracteristicasDAO();
		}
		return instance;
	}

	@SuppressWarnings("unchecked")
	public List<Caracteristica> getCaracteristicas() {
		ArrayList<Caracteristica> listaCarac = null;
		Session session = HibernateUtils.currentSession();
		listaCarac = (ArrayList<Caracteristica>)session.createQuery("select c from Caracteristica c").list();
		for(Caracteristica caracteristica : listaCarac){
			Hibernate.initialize(caracteristica);
		}
		return listaCarac;
	}
	
    @SuppressWarnings("unchecked")
	public List<TipoCaracteristica> getAllTipoCaracteristicas(){
    	List<TipoCaracteristica> listaTipos = new ArrayList<TipoCaracteristica>();
    	Session session = HibernateUtils.currentSession();
    	listaTipos = session.createQuery("select tc from TipoCaracteristica tc").list();
    	return listaTipos;
    }
	
}
